package com.songlanyun.modules.recommendassist.controller.api;

import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;
import com.songlanyun.common.validator.ValidatorUtils;
import com.songlanyun.modules.account.controller.common.AbstractApiController;
import com.songlanyun.modules.recommendassist.entity.RecommendAssistEntity;
import com.songlanyun.modules.recommendassist.service.RecommendAssistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.ValidationUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;


/**
 * 推荐帮扶
 *
 * @author wuchao
 * @email songlanyun@gmail.com
 * @date 2022-08-06 09:24:43
 */
@RestController
@RequestMapping("/api/recommend/assist")
public class RecommendAssistApiController extends AbstractApiController {
    @Autowired
    private RecommendAssistService recommendAssistService;

    /**
     * 列表
     */
    @GetMapping("/page")
    //@RequiresPermissions(":recommendassist:list")
    public R page(@RequestParam Map<String, Object> params) {
        PageUtils page = recommendAssistService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    //@RequiresPermissions(":recommendassist:info")
    public R info(@PathVariable("id") Long id) {
        RecommendAssistEntity recommendAssist = recommendAssistService.getById(id);

        return R.ok().put("data", recommendAssist);
    }

    /**
     * 提交
     */
    @PostMapping("/submit")
    //@RequiresPermissions(":recommendassist:save")
    public R submit(@RequestBody RecommendAssistEntity recommendAssist) {
        ValidatorUtils.validateEntity(recommendAssist);
        recommendAssist.setUserId(getUserId(true));
        recommendAssist.setStatus(0);
        recommendAssistService.save(recommendAssist);

        return R.ok();
    }

}
